package cn.ccenjie.wsy.dao;

import cn.ccenjie.wsy.entity.UserToken;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Repository
public interface UserTokenDao extends JpaRepository<UserToken, Integer> {

    UserToken findByUserId(String userId);

    @Modifying
    @Transactional
    @Query(value = "UPDATE UserToken set token = :token,exptime = :exptime where id = :id")
    void updateToken(@Param("token") String token, @Param("exptime") Date exptime, @Param("id") Integer id);

}
